<?php

namespace App\Models\product;

use App\Models\BaseModel;

class ProductModel extends BaseModel
{
    protected $table = 'product';
    protected $primaryKey = 'id';

//    use SoftDeletes;

    /**
     * 获取产品类型
     */
    public static function getProductType($value=''): array|string
    {
        $type = [
            1 => 'APP',
            2 => '小程序',
            3 => '平台',
            4 => '其他',
        ];
        if ( is_numeric($value) && $value > 0 && $value < 5 ) {
            return $type[$value];
        }
        if (is_string($value) && $value != '') {
            return array_search($value, $type);
        }
        return $type;
    }


    /**
     * 获取上线平台
     */
    public static function getOnlinePlatform($value=''): array|string
    {
        $platform = [
            1 => '微信',
            2 => '抖音',
            3 => '链接',
            4 => '支付宝'
        ];
        if ( is_numeric($value) && $value > 0 && $value < 6 ) {
            return $platform[$value];
        }
        if (is_string($value) && $value != '') {
            return array_search($value, $platform);
        }
        return $platform;
    }


    /**
     * 获取归属类型
     */
    public static function getBelongType($value=''): array|string
    {
        $type = [
            1 => '自有产品、无需身份弹窗',
            2 => '自有产品、需要身份弹窗',
            3 => '供应商上传',
        ];
        if ( is_numeric($value) && $value > 0 && $value < 4 ) {
            return $type[$value];
        }
        if (is_string($value) && $value != '') {
            return array_search($value, $type);
        }
        return $type;
    }


    /**
     * 获取产品分类
     */
    public function productClass(): \Illuminate\Database\Eloquent\Relations\BelongsTo
    {
        return $this->belongsTo(ProductClassModel::class, 'class_id', 'id');
    }


    // 获取产品归属
    public function productBelong(): \Illuminate\Database\Eloquent\Relations\BelongsTo
    {
        return $this->belongsTo(ProductBelongModel::class, 'belong_id', 'id');
    }


    // 获取子产品
    public function productSon(): \Illuminate\Database\Eloquent\Relations\HasMany
    {
        return $this->hasMany(ProductSonModel::class, 'product_id', 'id');
    }


    /**
     * 获取课程
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function productCourse(): \Illuminate\Database\Eloquent\Relations\BelongsTo
    {
        return $this->belongsTo(ProductCourseModel::class, 'course_id', 'id');
    }
}
